package com.shell.governor.srvhall.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.file.utils.FileHelper;
import com.shell.bee.persistence.annotation.Pagination;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.governor.srvhall.dao.PubSrvHallItemDao;
import com.shell.governor.srvhall.po.PubSrvHallItem;
import com.shell.governor.srvhall.service.PubSrvHallItemService;
import com.shell.governor.srvhall.vo.SrvHallItemVo;

@Service
public class PubSrvHallItemServiceImpl extends PersistentServiceImpl<PubSrvHallItem> implements PubSrvHallItemService {
	@Autowired
	private PubSrvHallItemDao pubSrvHallItemDao;

	@Pagination
	public List<SrvHallItemVo> getSrvHallItemByPage(PageLimit limit, String itemCategory, String hot,
			String searchStr) {
		searchStr = StringUtil.getParameterLike(searchStr);
		return this.pubSrvHallItemDao.getSrvHallItemByPage(itemCategory, hot, searchStr);
	}

	public void saveOrUpdateItem(SrvHallItemVo vo) {
		String fileIds = vo.getFileIds();
		if (StringUtil.notEmpty(fileIds)) {
			FileHelper.clearRelateId(vo.getItemId(), vo.getItemCategory());
			FileHelper.setRelateId(fileIds, vo.getItemId(), vo.getItemCategory());
		}
		PubSrvHallItem hallItem = new PubSrvHallItem();
		BeanUtils.copyProperties(vo, hallItem);
		saveOrUpdate(hallItem);
	}
}
